import rsa
import os
import base64
import urllib3
import time
'''
(pubkey, privkey) = rsa.newkeys(512)
print(pubkey.save_pkcs1().decode())
print(privkey.save_pkcs1().decode())
'''
with open(os.path.dirname(__file__)+'/GLBFLH9V.key','r') as f:
    privkey = rsa.PrivateKey.load_pkcs1(f.read().encode())

#print(privkey.save_pkcs1().decode())
message = str(int(time.time())).encode('utf8')
print(message)
signature = rsa.sign(message, privkey, 'SHA-256')
signature=base64.b64encode(signature).decode()

url="http://zthubo.sinaapp.com/dns/index.php"
body = {"s":signature, "m": message}
headers = {'content-type': "application/json"}

http=urllib3.PoolManager()
r=http.request('POST',url,headers=headers,fields=body)
d=r.data
print(body)
print(d)
with open(os.path.dirname(__file__)+"/ip.log","a+") as file:
    file.write(d.decode()+"\n")
